#!/bin/bash
type tar >/dev/null 2>&1 || exit 1
# root path
root=$1
# $1 root_path_name $2 sub_folder_name
doCompressLog(){
  year=$(date -d "yesterday" +%Y)
  month=$(date -d "yesterday" +%m)
  yesterday=$(date -d "yesterday" +%d)
  folder="/www/wwwroot/$1/source/runtime/log/${year}${month}/$2"
  if [ ! -e $folder ]
  then
    echo 'folder not exist'
    exit 1
  fi
  echo ${folder}
  cd ${folder}
  fileCount=`ls *-${yesterday}'.log' | wc -l`
  if [ ${fileCount} -gt 0 ]
  then
   tar -czf ${yesterday}.tar.gz *-${yesterday}.log
   if [ $? == 0 ]
   then
       rm -f *-${yesterday}.log
   fi
  fi
}

doCompressLog ${root} 'weigudong'
doCompressLog ${root} 'prepay'
doCompressLog ${root} 'notify'


